package com.raycloud.manager.msgqueue.impl;

import java.util.concurrent.ConcurrentLinkedQueue;

import javax.servlet.ServletContext;

import org.springframework.web.context.ServletContextAware;

import com.raycloud.common.ScopeConstants;
import com.raycloud.domain.MsgDistributeJob;
import com.raycloud.manager.msgqueue.IMsgQueueCreator;

/**
 * 消息队列的生产者，负责把消息插入消息队列，此处实现较为简单只是为了描述生产者-消费者模型中的生产者，
 * 后面随着消息队列的功能健壮会越来越复杂
 * @author wangyi
 *
 */
public class MsgQueueCreator implements IMsgQueueCreator, ServletContextAware {
	private ServletContext sc;

	public void setServletContext(ServletContext sc) {
		this.sc = sc;
	}

	@SuppressWarnings("unchecked")
	public void createJob(MsgDistributeJob job) {
		ConcurrentLinkedQueue<MsgDistributeJob> jobQueue = (ConcurrentLinkedQueue<MsgDistributeJob>) sc.getAttribute(ScopeConstants.JOB_QUEUE);
		
		jobQueue.add(job);
	}
	
}
